Page({
  data: {
    dialogVisible: false,
    houseList: [],

  },
  onLoad(){
    this.gethouseList()
  },
  // 获取房屋列表渲染显示
  async gethouseList(){
    let houseList = await wx.http.get('/room')
    this.setData({houseList})
    console.log(houseList);
  },
// 滑动事件
  swipeClose(ev) {
    this.cellId= ev.mark.id
    const { position, instance } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail({mark}) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id='+ mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
  // 确定弹框的关闭
  async dialogClose(event){
    // 不是确定就跳出
    if(event.detail !=="confirm") return
    // 删除逻辑
    await wx.http.delete('/room/'+ this.cellId)
    // 提示
    wx.utils.toast('删除成功')
    // 更新页面
    this.gethouseList()

  }
})
